package com.jy.modules.cims.component.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//import com.jy.modules.cims.common.sysUtils.SpringContextUtils;
import com.jy.modules.cims.common.sysUtils.SimpleStringUtils;
import com.jy.modules.cims.data.dao.ImgurlUtilsDao;

@Service("com.jy.modules.cims.component.common.ImgurlUtils")
public class ImgurlUtils {
	public static Map attTypeMap = new HashMap();
	
   // @Autowired
   // public SpringContextUtils springContextUtil;

    @Autowired
    ImgurlUtilsDao imgurlUtilsDao;

    /**
     * 附件类型缓存key值
     */
   // private final String CIMS_ATTTYPE = "hzjg_cims_attType";
    
    /**
     * 缓存超时时间
     */
   // private final int EXPIRE_TIME = 60*60;

    /**
     * 根据附件名称获取附件类型的值
     * 
     * @param attachName T_C_MM_IMGURL表ATTACH_NAME字段附件名称
     * @return 附件类型的值
     */
    public String getAttachType(String attachName) {
        //JedisSentinelPool jedisSentinelPool = springContextUtil.getBean("jedisSentinelPool");
        //ShardedJedis jedis = jedisSentinelPool.getResource();
        //jedis.expire(CIMS_ATTTYPE, EXPIRE_TIME);//超时时间
       // Map attTypeMap = jedis.hgetAll(CIMS_ATTTYPE);
    	
       if (attTypeMap == null ||attTypeMap.isEmpty()) {
            List<Map> list = imgurlUtilsDao.getCimsAttType();
           // Map map = new HashMap();
            for(Map m:list){
            	attTypeMap.put(m.get("DICT_DETAIL_VALUE"), m.get("DICT_DETAIL_NAME"));
            }
  
       }
       
        if (!SimpleStringUtils.hasText(attachName)) {
            return null;
        }
        int index = attachName.indexOf("_");
        if (index > 0) {
            String att = attachName.substring(0, index);
            Object type = attTypeMap.get(att);
            if (null == type) {
                return "其他";
            } else {
                return type.toString();
            }
        }
        return "其他"; // 附件类型：其他
    }
}
